
<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>WTForms Documentation</title>
    <link rel="stylesheet" href="_static/main.css" type="text/css">
    <link rel="stylesheet" href="_static/docstyles.css" type="text/css">
    <link rel="stylesheet" href="_static/print.css" type="text/css" media="print">
    <link rel="stylesheet" href="_static/pygments.css" type="text/css">
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:   '#',
        VERSION:    '1.0.4'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/searchtools.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="contents" title="Global table of contents" href="contents.html">
    <link rel="index" title="Global index" href="genindex.html">
    <link rel="search" title="Search" href="search.html">
    <link rel="top" title="WTForms 1.0.4 documentation" href="index.html">
    <link rel="next" title="Fields" href="fields.html">
    <link rel="prev" title="WTForms Documentation" href="index.html">
    
  </head>
  <body>
    <div id="body">
      <div id="header">
        <h1 id="logo"><a href="index.html"
          title="back to the documentation overview"><img src="_static/wtforms.png" alt="WTForms" /></a></h1>
        <ul id="menu">
          <li><a href="http://wtforms.simplecodes.com/">Website</li>
          <li><a href="index.html">Documentation</a></li>
          <li><a href="faq.html">FAQ</a></li>
          <li><a href="http://groups.google.com/group/wtforms/">Mailing List</a></li>
          <li><a href="http://bitbucket.org/simplecodes/wtforms/">Code</a></li>
        </ul>
      </div>
      <div id="content">
        <div id="toc">
          <h3>Table Of Contents</h3>
          <div class="inner"><ul>
<li><a class="reference internal" href="#">Forms</a><ul>
<li><a class="reference internal" href="#the-form-class">The Form class</a></li>
<li><a class="reference internal" href="#defining-forms">Defining Forms</a><ul>
<li><a class="reference internal" href="#form-inheritance">Form Inheritance</a></li>
<li><a class="reference internal" href="#in-line-validators">In-line Validators</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-forms">Using Forms</a></li>
<li><a class="reference internal" href="#low-level-api">Low-Level API</a></li>
</ul>
</li>
</ul>
</div>
        </div>
        
  <div class="section" id="module-wtforms.form">
<span id="forms"></span><h1>Forms<a class="headerlink" href="#module-wtforms.form" title="Permalink to this headline">¶</a></h1>
<p>Forms provide the highest level API in WTForms. They contain your field
definitions, delegate validation, take input, aggregate errors, and in
general function as the glue holding everything together.</p>
<div class="section" id="the-form-class">
<h2>The Form class<a class="headerlink" href="#the-form-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="wtforms.form.Form">
<em class="property">class </em><tt class="descclassname">wtforms.form.</tt><tt class="descname">Form</tt><a class="headerlink" href="#wtforms.form.Form" title="Permalink to this definition">¶</a></dt>
<dd><p>Declarative Form base class.</p>
<p><strong>Construction</strong></p>
<dl class="method">
<dt id="wtforms.form.Form.__init__">
<tt class="descname">__init__</tt><big>(</big><em>formdata=None</em>, <em>obj=None</em>, <em>prefix=''</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#wtforms.form.Form.__init__" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>formdata</strong> &#8211; Used to pass data coming from the enduser, usually <cite>request.POST</cite> or
equivalent. formdata should be some sort of request-data wrapper which
can get multiple parameters from the form input, and values are unicode
strings, e.g. a Werkzeug/Django/WebOb MultiDict</li>
<li><strong>obj</strong> &#8211; If <cite>formdata</cite> is empty or not provided, this object is checked for
attributes matching form field names, which will be used for field
values.</li>
<li><strong>prefix</strong> &#8211; If provided, all fields will have their name prefixed with the
value.</li>
<li><strong>**kwargs</strong> &#8211; If <cite>formdata</cite> is empty or not provided and <cite>obj</cite> does not contain
an attribute named the same as a field, form will assign the value
of a matching keyword argument to the field, if one exists.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Initialize a Form. This is usually done in the context of a
view/controller in your application. When a Form is constructed, the
fields populate their input based on the formdata, obj, and kwargs.</p>
<p><strong>Note</strong>
Backing-store objects and kwargs are both expected to be provided
with the values being already-coerced datatypes. WTForms does not
check the types of incoming object-data or coerce them like it will
for <cite>formdata</cite> as it is expected this data is defaults or data from
a backing store which this form represents. See the section on
<a class="reference internal" href="#using-forms"><em>using Forms</em></a> for more information.</p>
</dd></dl>

<p><strong>Properties</strong></p>
<dl class="attribute">
<dt id="wtforms.form.Form.data">
<tt class="descname">data</tt><a class="headerlink" href="#wtforms.form.Form.data" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict containing the data for each field.</p>
<p>Note that this is generated each time you access the property, so care
should be taken when using it, as it can potentially be very expensive
if you repeatedly access it. Typically used if you need to iterate all
data in the form. If you just need to access the data for known fields,
you should use <cite>form.&lt;field&gt;.data</cite>, not this proxy property.</p>
</dd></dl>

<dl class="attribute">
<dt id="wtforms.form.Form.errors">
<tt class="descname">errors</tt><a class="headerlink" href="#wtforms.form.Form.errors" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict containing a list of errors for each field. Empty if the form
hasn&#8217;t been validated, or there were no errors.</p>
<p>Note that this is a lazy property, and will only be generated when you
first access it. If you call <a class="reference internal" href="#wtforms.form.Form.validate" title="wtforms.form.Form.validate"><tt class="xref py py-meth docutils literal"><span class="pre">validate()</span></tt></a> after accessing it, the
cached result will be invalidated and regenerated on next access.</p>
</dd></dl>

<p><strong>Methods</strong></p>
<dl class="method">
<dt id="wtforms.form.Form.validate">
<tt class="descname">validate</tt><big>(</big><big>)</big><a class="headerlink" href="#wtforms.form.Form.validate" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates the form by calling <cite>validate</cite> on each field, passing any
extra <cite>Form.validate_&lt;fieldname&gt;</cite> validators to the field validator.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.Form.populate_obj">
<tt class="descname">populate_obj</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#wtforms.form.Form.populate_obj" title="Permalink to this definition">¶</a></dt>
<dd><p>Populates the attributes of the passed <cite>obj</cite> with data from the form&#8217;s
fields.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Note :</th><td class="field-body">This is a destructive operation; Any attribute with the same name
as a field will be overridden. Use with caution.</td>
</tr>
</tbody>
</table>
<p>One common usage of this is an edit profile view:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">edit_profile</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="p">[</span><span class="s">&#39;userid&#39;</span><span class="p">])</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">EditProfileForm</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="n">user</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span> <span class="ow">and</span> <span class="n">form</span><span class="o">.</span><span class="n">validate</span><span class="p">():</span>
        <span class="n">form</span><span class="o">.</span><span class="n">populate_obj</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
        <span class="n">user</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="s">&#39;/home&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">&#39;edit_profile.html&#39;</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">)</span>
</pre></div>
</div>
<p>In the above example, because the form isn&#8217;t directly tied to the user
object, you don&#8217;t have to worry about any dirty data getting onto there
until you&#8217;re ready to move it over.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.Form.__iter__">
<tt class="descname">__iter__</tt><big>(</big><big>)</big><a class="headerlink" href="#wtforms.form.Form.__iter__" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate form fields in their order of definition on the form.</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">for</span> <span class="nv">field</span> <span class="k">in</span> <span class="nv">form</span> <span class="cp">%}</span><span class="x"></span>
<span class="x">    &lt;tr&gt;</span>
<span class="x">        &lt;th&gt;</span><span class="cp">{{</span> <span class="nv">field.label</span> <span class="cp">}}</span><span class="x">&lt;/th&gt;</span>
<span class="x">        &lt;td&gt;</span><span class="cp">{{</span> <span class="nv">field</span> <span class="cp">}}</span><span class="x">&lt;/td&gt;</span>
<span class="x">    &lt;/tr&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.Form.__contains__">
<tt class="descname">__contains__</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#wtforms.form.Form.__contains__" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <cite>True</cite> if the named field is a member of this form.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.Form._get_translations">
<tt class="descname">_get_translations</tt><big>(</big><big>)</big><a class="headerlink" href="#wtforms.form.Form._get_translations" title="Permalink to this definition">¶</a></dt>
<dd><p>Override in subclasses to provide alternate translations factory.</p>
<p>Must return an object that provides gettext() and ngettext() methods.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="defining-forms">
<h2>Defining Forms<a class="headerlink" href="#defining-forms" title="Permalink to this headline">¶</a></h2>
<p>To define a form, one makes a subclass of <a class="reference internal" href="#wtforms.form.Form" title="wtforms.form.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> and defines the fields
declaratively as class attributes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyForm</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">TextField</span><span class="p">(</span><span class="s">u&#39;First Name&#39;</span><span class="p">,</span> <span class="n">validators</span><span class="o">=</span><span class="p">[</span><span class="n">validators</span><span class="o">.</span><span class="n">required</span><span class="p">()])</span>
    <span class="n">last_name</span>  <span class="o">=</span> <span class="n">TextField</span><span class="p">(</span><span class="s">u&#39;Last Name&#39;</span><span class="p">,</span> <span class="n">validators</span><span class="o">=</span><span class="p">[</span><span class="n">validators</span><span class="o">.</span><span class="n">optional</span><span class="p">()])</span>
</pre></div>
</div>
<p>Field names can be any valid python identifier, with the following restrictions:</p>
<ul class="simple">
<li>Field names are case-sensitive.</li>
<li>Field names may not begin with &#8220;_&#8221; (underscore)</li>
<li>Field names may not begin with &#8220;validate&#8221;</li>
</ul>
<div class="section" id="form-inheritance">
<h3>Form Inheritance<a class="headerlink" href="#form-inheritance" title="Permalink to this headline">¶</a></h3>
<p>Forms may subclass other forms as needed.  The new form will contain all fields
of the parent form, as well as any new fields defined on the subclass.  A field
name re-used on a subclass causes the new definition to obscure the original.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PastebinEdit</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">language</span> <span class="o">=</span> <span class="n">SelectField</span><span class="p">(</span><span class="s">u&#39;Programming Language&#39;</span><span class="p">,</span> <span class="n">choices</span><span class="o">=</span><span class="n">PASTEBIN_LANGUAGES</span><span class="p">)</span>
    <span class="n">code</span>     <span class="o">=</span> <span class="n">TextAreaField</span><span class="p">()</span>

<span class="k">class</span> <span class="nc">PastebinEntry</span><span class="p">(</span><span class="n">PastebinEdit</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">TextField</span><span class="p">(</span><span class="s">u&#39;User Name&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="in-line-validators">
<span id="inline-validators"></span><h3>In-line Validators<a class="headerlink" href="#in-line-validators" title="Permalink to this headline">¶</a></h3>
<p>In order to provide custom validation for a single field without needing to
write a one-time-use validator, validation can be defined inline by defining a
method with the convention <cite>validate_fieldname</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">SignupForm</span><span class="p">(</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">age</span> <span class="o">=</span> <span class="n">IntegerField</span><span class="p">(</span><span class="s">u&#39;Age&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">validate_age</span><span class="p">(</span><span class="n">form</span><span class="p">,</span> <span class="n">field</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">field</span><span class="o">.</span><span class="n">data</span> <span class="o">&lt;</span> <span class="mi">13</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ValidationError</span><span class="p">(</span><span class="s">&quot;We&#39;re sorry, you must be 13 or older to register&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="using-forms">
<span id="id1"></span><h2>Using Forms<a class="headerlink" href="#using-forms" title="Permalink to this headline">¶</a></h2>
<p>A form is most often constructed in the controller code for handling an action,
with the form data wrapper from the framework passed to its constructor, and
optionally an ORM object. A typical view begins something like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">edit_article</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">article</span> <span class="o">=</span> <span class="n">Article</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">MyForm</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">,</span> <span class="n">article</span><span class="p">)</span>
</pre></div>
</div>
<p>A typical CRUD view has a user editing an object that needs various fields
updated. The Form would have fields describing the fields to be updated and
the validation rules, where the attribute names of the fields match those of
the attribute names on the object. The second parameter to the Form, the <cite>obj</cite>
parameter, is used to populate form defaults on the initial view.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>While we did pass an object as the data source, this object data is only
used if there is no POST data. If there is any POST data at all, then the
object data is ignored. This is done for security and consistency reasons.</p>
<p class="last">This pattern is mostly a convenience since most application controllers
don&#8217;t separate GET and POST requests into separate view methods.</p>
</div>
<p>The constructed form can then validate any input data and generate errors if
invalid. Typically, the validation pattern in the view looks like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span> <span class="ow">and</span> <span class="n">form</span><span class="o">.</span><span class="n">validate</span><span class="p">():</span>
    <span class="n">form</span><span class="o">.</span><span class="n">populate_obj</span><span class="p">(</span><span class="n">article</span><span class="p">)</span>
    <span class="n">article</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="s">&#39;/articles&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that we have it so <a class="reference internal" href="#wtforms.form.Form.validate" title="wtforms.form.Form.validate"><tt class="xref py py-meth docutils literal"><span class="pre">validate()</span></tt></a> is only called if there is
POST data. The reason we gate the validation check this way is that when
there is no POST data (such as in a typical CRUD form) we don&#8217;t want to
cause validation errors.</p>
<p>Inside the gated block, we call <a class="reference internal" href="#wtforms.form.Form.populate_obj" title="wtforms.form.Form.populate_obj"><tt class="xref py py-meth docutils literal"><span class="pre">populate_obj()</span></tt></a> to copy the data
onto fields on the &#8216;article&#8217; object. We also then redirect after a successful
completion. The reason we redirect after the post is a best-practice associated
with the <a class="reference external" href="http://en.wikipedia.org/wiki/Post/Redirect/Get">Post/Redirect/Get</a>
design pattern.</p>
<p>If there is no POST data, or the data fails to validate, then the view &#8220;falls
through&#8221; to the rendering portion. The Form object can be passed into the
template and its attributes can be used to render the fields and also for
displaying errors:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="s">&#39;edit.html&#39;</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">,</span> <span class="n">article</span><span class="o">=</span><span class="n">article</span><span class="p">)</span>
</pre></div>
</div>
<p>So there we have a full simple &#8220;edit object&#8221; page setup which
illustrates a best-practice way of using WTForms. This is by no means the only
way to use WTForms, but just an illustration of how the various features work.</p>
<p>Here is the full code for the view we just made:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">edit_article</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">article</span> <span class="o">=</span> <span class="n">Article</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">MyForm</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">,</span> <span class="n">article</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span> <span class="ow">and</span> <span class="n">form</span><span class="o">.</span><span class="n">validate</span><span class="p">():</span>
        <span class="n">form</span><span class="o">.</span><span class="n">populate_obj</span><span class="p">(</span><span class="n">article</span><span class="p">)</span>
        <span class="n">article</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="s">&#39;/articles&#39;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="s">&#39;edit.html&#39;</span><span class="p">,</span> <span class="n">form</span><span class="o">=</span><span class="n">form</span><span class="p">,</span> <span class="n">article</span><span class="o">=</span><span class="n">article</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="low-level-api">
<h2>Low-Level API<a class="headerlink" href="#low-level-api" title="Permalink to this headline">¶</a></h2>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">This section is provided for completeness; and is aimed at authors of
complementary libraries and those looking for very special behaviors.
Don&#8217;t use <cite>BaseForm</cite> unless you know exactly <em>why</em> you are using it.</p>
</div>
<p>For those looking to customize how WTForms works, for libraries or special
applications, it might be worth using the <a class="reference internal" href="#wtforms.form.BaseForm" title="wtforms.form.BaseForm"><tt class="xref py py-class docutils literal"><span class="pre">BaseForm</span></tt></a> class. <cite>BaseForm</cite> is
the parent class of <a class="reference internal" href="#wtforms.form.Form" title="wtforms.form.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a>, and most of the implementation
logic from Form is actually handled by BaseForm.</p>
<p>The major difference on the surface between <cite>BaseForm</cite> and <cite>Form</cite> is that
fields are not defined declaratively on a subclass of <cite>BaseForm</cite>. Instead, you
must pass a dict of fields to the constructor. Likewise, you cannot add fields
by inheritance. In addition, <cite>BaseForm</cite> does not provide: sorting fields by
definition order, or inline <cite>validate_foo</cite> validators.  Because of this, for
the overwhelming majority of uses we recommend you use Form instead of BaseForm
in your code.</p>
<p>What <cite>BaseForm</cite> provides is a container for a collection of fields, which
it will bind at instantiation, and hold in an internal dict. Dict-style access
on a BaseForm instance will allow you to access (and modify) the enclosed
fields.</p>
<dl class="class">
<dt id="wtforms.form.BaseForm">
<em class="property">class </em><tt class="descclassname">wtforms.form.</tt><tt class="descname">BaseForm</tt><big>(</big><em>fields</em>, <em>prefix=''</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm" title="Permalink to this definition">¶</a></dt>
<dd><p>Base Form Class.  Provides core behaviour like field construction,
validation, and data and error proxying.</p>
<p><strong>Construction</strong></p>
<dl class="method">
<dt id="wtforms.form.BaseForm.__init__">
<tt class="descname">__init__</tt><big>(</big><em>fields</em>, <em>prefix=''</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.__init__" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>fields</strong> &#8211; A dict or sequence of 2-tuples of partially-constructed fields.</li>
<li><strong>prefix</strong> &#8211; If provided, all fields will have their name prefixed with the
value.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="n">form</span> <span class="o">=</span> <span class="n">BaseForm</span><span class="p">({</span>
    <span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="n">TextField</span><span class="p">(),</span>
    <span class="s">&#39;customer.age&#39;</span><span class="p">:</span> <span class="n">IntegerField</span><span class="p">(</span><span class="s">&quot;Customer&#39;s Age&quot;</span><span class="p">)</span>
<span class="p">})</span>
</pre></div>
</div>
<p>Because BaseForm does not require field names to be valid identifiers,
they can be most any python string. We recommend keeping it
simple to avoid incompatibility with browsers and various form input
frameworks where possible.</p>
</dd></dl>

<p><strong>Properties</strong></p>
<dl class="attribute">
<dt id="wtforms.form.BaseForm.data">
<tt class="descname">data</tt><a class="headerlink" href="#wtforms.form.BaseForm.data" title="Permalink to this definition">¶</a></dt>
<dd><p>see <a class="reference internal" href="#wtforms.form.Form.data" title="wtforms.form.Form.data"><tt class="xref py py-attr docutils literal"><span class="pre">Form.data</span></tt></a></p>
</dd></dl>

<dl class="attribute">
<dt id="wtforms.form.BaseForm.errors">
<tt class="descname">errors</tt><a class="headerlink" href="#wtforms.form.BaseForm.errors" title="Permalink to this definition">¶</a></dt>
<dd><p>see <a class="reference internal" href="#wtforms.form.Form.errors" title="wtforms.form.Form.errors"><tt class="xref py py-attr docutils literal"><span class="pre">Form.errors</span></tt></a></p>
</dd></dl>

<p><strong>Methods</strong></p>
<dl class="method">
<dt id="wtforms.form.BaseForm.process">
<tt class="descname">process</tt><big>(</big><em>formdata=None</em>, <em>obj=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.process" title="Permalink to this definition">¶</a></dt>
<dd><p>Take form, object data, and keyword arg input and have the fields
process them.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>formdata</strong> &#8211; Used to pass data coming from the enduser, usually <cite>request.POST</cite> or
equivalent.</li>
<li><strong>obj</strong> &#8211; If <cite>formdata</cite> is empty or not provided, this object is checked for
attributes matching form field names, which will be used for field
values.</li>
<li><strong>**kwargs</strong> &#8211; If <cite>formdata</cite> is empty or not provided and <cite>obj</cite> does not contain
an attribute named the same as a field, form will assign the value
of a matching keyword argument to the field, if one exists.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Since BaseForm does not take its data at instantiation, you must call
this to provide form data to the enclosed fields. Accessing the field&#8217;s
data before calling process is not recommended.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.BaseForm.validate">
<tt class="descname">validate</tt><big>(</big><em>extra_validators=None</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.validate" title="Permalink to this definition">¶</a></dt>
<dd><p>Validates the form by calling <cite>validate</cite> on each field.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>extra_validators</strong> &#8211; If provided, is a dict mapping field names to a sequence of
callables which will be passed as extra validators to the field&#8217;s
<cite>validate</cite> method.</td>
</tr>
</tbody>
</table>
<p>Returns <cite>True</cite> if no errors occur.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.BaseForm.__iter__">
<tt class="descname">__iter__</tt><big>(</big><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.__iter__" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterate form fields in arbitrary order</p>
<p>Unlike <a class="reference internal" href="#wtforms.form.Form" title="wtforms.form.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a>, fields are not iterated in definition order, but
rather in whatever order the dict decides to yield them.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.BaseForm.__contains__">
<tt class="descname">__contains__</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.__contains__" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <cite>True</cite> if the named field is a member of this form.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.BaseForm.__getitem__">
<tt class="descname">__getitem__</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.__getitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>Dict-style access to this form&#8217;s fields.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.BaseForm.__setitem__">
<tt class="descname">__setitem__</tt><big>(</big><em>name</em>, <em>value</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.__setitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>Bind a field to this form.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">form</span><span class="p">[</span><span class="s">&#39;openid.name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">TextField</span><span class="p">()</span>
</pre></div>
</div>
<p>Fields can be added and replaced in this way, but this must be done
<strong>before</strong> <a class="reference internal" href="#wtforms.form.BaseForm.process" title="wtforms.form.BaseForm.process"><tt class="xref py py-meth docutils literal"><span class="pre">process()</span></tt></a> is called, or the fields will not have the
opportunity to receive input data. Similarly, changing fields after
<a class="reference internal" href="#wtforms.form.BaseForm.validate" title="wtforms.form.BaseForm.validate"><tt class="xref py py-meth docutils literal"><span class="pre">validate()</span></tt></a> will have undesired effects.</p>
</dd></dl>

<dl class="method">
<dt id="wtforms.form.BaseForm.__delitem__">
<tt class="descname">__delitem__</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#wtforms.form.BaseForm.__delitem__" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove a field from this form.</p>
<p>The same caveats apply as with <a class="reference internal" href="#wtforms.form.BaseForm.__setitem__" title="wtforms.form.BaseForm.__setitem__"><tt class="xref py py-meth docutils literal"><span class="pre">__setitem__()</span></tt></a>.</p>
</dd></dl>

</dd></dl>

</div>
</div>


        <div style="clear: both"></div>
      </div>
      <div id="footer">
        © Copyright 2010 by the <a href="http://wtforms.simplecodes.com">WTForms Team</a>,
        documentation generated by <a href="http://sphinx.pocoo.org/">Sphinx</a>
      </div>
    </div>
  </body>
</html>